Repository navigation
Tests: Restore the original $wp_rewrite after each Tests_Rewrite_Tags test. - #16250
mayankmajeji wants to merge 1 commit into
Conversation
…ags` test. The class replaced the global with a new `WP_Rewrite` that lacks the rules registered at load time, such as the sitemap rules, so later classes resolved sitemap URLs through the page rule. Restore the original object in `tear_down()`. See #66755.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the test-isolation change that preserves and restores the global $wp_rewrite instance.
No open issues 🎉
What changed in this PR
This PR improves test isolation by restoring the original global $wp_rewrite after each Tests_Rewrite_Tags test, preventing replacement rewrite state from affecting later tests, including canonical sitemap tests.
Changes:
- Saves the original
WP_Rewriteinstance during setup. - Restores it during teardown, before calling
parent::tear_down().
| File | Description |
|---|---|
tests/phpunit/tests/rewrite/rewriteTags.php |
Preserves and restores the global rewrite instance around each test. |
Review effort: Balanced
lancewillett
left a comment
There was a problem hiding this comment.
I reproduced the sitemap redirect failure after the rewrite-tag tests on single-site and multisite. Restoring the original rewrite object kept its registered sitemap rules and made both runs pass (13 tests, 126 assertions each).
AI review · gpt-6.2-astra
Keep the sitemap rules registered at bootstrap available to subsequent canonical redirect tests. Developed in: #16250 Props mayankmajeji. See #66755. git-svn-id: https://develop.svn.wordpress.org/trunk@65796 602fd350-edb4-49c9-b593-d223f7449a82
|
PR #16250 landed in https://core.trac.wordpress.org/changeset/65796 |
Keep the sitemap rules registered at bootstrap available to subsequent canonical redirect tests. Developed in: WordPress/wordpress-develop#16250 Props mayankmajeji. See #66755. Built from https://develop.svn.wordpress.org/trunk@65796 git-svn-id: http://core.svn.wordpress.org/trunk@64825 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Trac ticket: https://core.trac.wordpress.org/ticket/66755
Tests_Rewrite_Tags::set_up()replaces the global$wp_rewritewith a newWP_Rewriteand never puts the original back, so every later class runs with that new object. The new object does not have the rewrite rules registered while WordPress loaded, such as the sitemap rules fromWP_Sitemaps::register_rewrites(), and the rules it generates are kept.Tests_Canonical_Sitemaps::set_up()adds the sitemap rules again, but they are not in the generated rules./wp-sitemap-posts-post-1.xml/then matches the page rule (pagename=wp-sitemap-posts-post-1.xml) instead of the sitemap rule, so there is nositemapquery var andredirect_canonical()does not remove the trailing slash. The index URL fails the same way:test_remove_trailing_slashes_for_sitemap_index_requests()gets/wp-sitemap.xml/instead of/wp-sitemap.xml.test_remove_trailing_slashes_for_sitemap_requests()gets/wp-sitemap-posts-post-1.xml/instead of/wp-sitemap-posts-post-1.xml.Whichever of the two runs first in
Tests_Canonical_Sitemapsfails, and both pass on their own.What changes
Tests_Rewrite_Tagskeeps the$wp_rewritefrom before each test and restores it in a newtear_down(), beforeparent::tear_down().Testing
Locally with PHP 8.4.28, MySQL 9.7.4 and PHPUnit 9.6.39, on trunk at r65788.
The config below runs
rewrite/rewriteTags.phpand thencanonical/sitemaps.php.vendor/bin/phpunit -c pair.xml: 1 failure on trunk (test_remove_trailing_slashes_for_sitemap_index_requests(),/wp-sitemap.xml/), OK (45 tests, 159 assertions) with this change.vendor/bin/phpunit -c pair.xml --filter '/^(?!Tests_Canonical_Sitemaps::)|::test_remove_trailing_slashes_for_sitemap_requests$/': 1 failure on trunk (/wp-sitemap-posts-post-1.xml/), OK (13 tests, 126 assertions) with this change.<const name="WP_TESTS_MULTISITE" value="1" />added).Tests_Rewrite_Tagsin default order, with--order-by=reverse, with--order-by=random --random-order-seed=7, and on multisite: OK with this change.--group rewrite(1038 tests, also on multisite),--group sitemaps(209 tests) and--group canonical(221 tests): no failures with this change.--order-by=random --random-order-seed=7on trunk at r65781 and narrowed torewrite/rewriteTags.phpby bisecting the 370 classes that ran before the sitemap test.Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Investigation, code, local testing and PR wording. I reviewed the reasoning, the code and the test results, and I take responsibility for the contribution.